package com.woniuxy.controller;

import com.woniuxy.service.impl.AppointmentService;
import com.woniuxy.util.Page;
import com.woniuxy.util.Result;
import com.woniuxy.vo.AppointmentVO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class AppointmentController {
    @Resource
    private AppointmentService appointmentService;

    @RequestMapping("/appointment/selectAppointment")
    public Result selectAppointment(Integer index, Integer number, String campName, String startTime, String endTime) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("index", index);
        map.put("number", number);
        map.put("campName", campName);
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        List<AppointmentVO> list = appointmentService.selectAppointmentByExample(map);
        int dataCount = appointmentService.countAppointment(map);
        int pageCount = dataCount % number == 0 ? dataCount / number : dataCount / number + 1;
        Page page = new Page();
        page.setNumber(number);
        page.setCount(dataCount);
        page.setPageCount(pageCount);
        page.setPageIndex(index);
        System.out.println(list);
        return new Result("200", "success", page, list);
    }
}
